{include file="public/public"}

<div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
    <div class="layui-body layui-tab-content site-demo site-demo-body">
        <div class="layui-tab-item layui-show">
            <div class="layui-main">
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                </fieldset>
                <span class="layui-breadcrumb">
	                   	<a href="__APP__/{$menuConfigArry['functionMod']}/{$menuConfigArry['menuLabel']}">{$menuConfigArry['pmenuName']}</a>
                    	<a><cite>{$menuConfigArry['menuName']}</cite></a>
	                </span>
                <hr>


                <div class="content_3_ss clear">
                    <ul>
                        <li><span class="ctt_wd left">酒店区域查找：</span>
                            <input id='souname'  name="text2" type="text" class="layui-input" />
                        </li>
                        <li class="ss_cx"><a href="#" onClick="subsou()">查询</a></li>
                        <li class="ss_cx"><a href="__APP__/admin/operationlog?type=hotelArea">操作日志</a></li>
                    </ul>
                </div>
                  <table class="layui-table" lay-skin="line" >
                   <thead >
                    <tr>
                        <td width="75">选择</td>
                        <td width="85">编号</td>
                        <td width="267">统计用户名</td>


                        <td width="180">操作</td>
                    </tr>
                    </thead>
                    <tbody>
                    <?
     if($roomArr){
      foreach($roomArr as $val){
        $tmp = addslashes(json_encode($val));
     ?>
                    <tr >
                        <td><input  type="checkbox" name="roombox" id="roombox"  value="{$val[userid]}"></td>
                        <td>{$val[userid]}</td>
                        <td>{$val[username]}</td>

                        <td>
                            <a href="#" class="layui-btn layui-btn-sm" onclick='edithotel("{$tmp}",2)'>关联酒店 </a>
                        </td>
                    </tr>
                    <?php
		}
	}?>
                    </tbody>
                </table>
                <div class="content_1234">
                    <div class="content_glcz">管理操作：全选
                        <input type="checkbox"  onClick="checkallstu(this)" />
                        <input name="submit" type="submit" value="删除"  onclick="delall()" class="layui-btn layui-btn-sm layui-btn-warm"/>
                        <input name="submit2" type="button" value="添加关联" onclick="aadd()" class="layui-btn layui-btn-sm"/>
                    </div>
                    <div class="layui-box layui-laypage layui-laypage-default">{$page}</div>
                </div>


                <FORM action="__APP__/admin/join_hotel_admin" enctype="multipart/form-data"method="post" >
                    <div id="showArea_hotel" style="DISPLAY:none" class="show">
                        <table class="layui-table" lay-skin="line">
                           <thead >
                            <tr>
                                <td colspan="2">统计用户关联管理</td>
                                <input type="hidden" id="areaid" name="areaid">

                            </tr>
                            </thead>
                            <tbody>
                            <tr class="ctt_gr">
                                <td width="154" align="right">统计用户：</td>
                                <td width="338" align="left"><select id="areaname" name="areaname">
                                    <option>选择用户</option>
                                    <?
                         if($adminArr){
                          foreach($adminArr as $val){
                         ?>
                                    <option value="{$val['id']}">{$val['username']}</option>
                                    <?
                        }}
                     ?>
                                </select>

                                </td>
                            </tr>
                            <tr class="ctt_gr">
                                <td  align="right">酒店名：</td>
                                <td align="left"><input  type="text" name="hotelname" id="hotelname"  readonly="readonly">
                                    <input name="button" type="button"  onclick="showinfo()" value="选择酒店"  class="btn_01"/></td>

                            </tr>


                            <tr class="ctt_gr">
                                <td height="31" colspan="2" align="center"><input name="submit22" type="submit" value="确定" border="0"  class="layui-btn" id="ok"/>
                                    <input name="submit22" type="button" value="取消" border="0" onclick="document.getElementById
	('showArea_hotel').style.display='none'" class="layui-btn layui-btn-warm"/></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>

                </FORM>

                <div id="showhotel" style="DISPLAY:none" class="show">
                    <table class="layui-table" lay-skin="line">
                       <thead >
                        <tr>
                            <td colspan="8">酒店列表</td>
                        </tr>
                        <tr>
                            <td class="ctt_white" colspan="7" align="center">酒店名：<input  type="text" name="movie_sou" id="hotel_sou" >
                                <input name="button" type="button"  onclick="sou_hotel()"  value="查询" border="0" />
                            </td>
                            <td class="ctt_white">全选：
                                <input name="checkbox" type="checkbox" onClick="checkallhotel(this)" />
                            </td>
                        </tr>
                        </thead>
                        <tbody id="hotel_ss">

                        </tbody>
                        <tfoot>
                        <tr class="ctt_gr">
                            <td height="31" colspan="8" align="center"><input name="button" type="button"  onclick="sureclick('hotel')"  value="确定" border="0"  class="layui-btn"/>
                                <input name="submit22" type="button" value="关闭" border="0" onclick="document.getElementById
	('showhotel').style.display='none'" class="layui-btn layui-btn-warm"/></td>
                        </tr>
                        </tfoot>
                    </table>
                </div>

            </div>
        </div>
    </div>
</div>
<script language="javascript">
function checkallstu(o) {
	if(o.checked){
		$("input[name='roombox']").attr("checked",true);
	}else{
		$("input[name='roombox']").attr("checked",false);
	}
}
function aadd(){
	$("#showArea_hotel").show();
}

function delall(){
    var arr="";
    $("input[name=roombox]:checked").each(function(){
    	arr+=$(this).val()+",";
    })
    if(arr==""){
    	alert('请选择要删除的记录');
		return false; 
    }
    if (confirm("您确定要删除吗？")){
         $.post("__APP__/admin/delallhotelAdmin",{
    	arr : arr
	    }, function(data) {
		if(data.msg=="1"){
			alert("删除成功");
			location.reload();
		}else{
			alert("删除失败");
	    	}
	    },"json");
    }else{
       return false;}
}
function edit(val,flag){
    var json=JSON.parse(val);

	$("#id").val(json.id);
	$("#hotel2").val(json.areaname);
    $("#show").show();
}
function edithotel(val,flag){
    var json=JSON.parse(val);
    var id=json.userid;
    $("#areaid").val(json.userid);
    $("#areaname").val(json.userid);
    $("#hotelname").val(json.hotel);
    $("#showArea_hotel").show();

}


function subsou(){
	var souname = $("#souname").val();
	window.location.href='__APP__/admin/hotelArea?groupname='+souname;
}

function sou_hotel(){
    var movie_sou = $("#hotel_sou").val();
    $.post("__APP__/admin/sou_hotel",{
        arr : movie_sou
    }, function(data) {
        if(data.msg=="1"){
            var json=data.moviesArr;
            var length=json.length;
            var i=1;
            var tempData = "";
            for (var data in json){
                if((i%4)==1){
                    tempData  =  tempData + "<tr class='ctt_white'> <td align='right'><input  type='checkbox' name='hotelbox' id='hotelbox'  value='"+json[data].id+"/"+json[data].hotel+"'><\/td><td align='left' width='90px'>"+json[data].hotel+"<\/td>";
                }else if((i%4)==0){
                    tempData  =  tempData + " <td align='right'><input  type='checkbox' name='hotelbox' id='hotelbox'  value='"+json[data].id+"/"+json[data].hotel+"'><\/td><td align='left' width='90px'>"+json[data].hotel+"<\/td><\/tr>";
                }else {
                    tempData  =  tempData + " <td align='right'><input  type='checkbox' name='hotelbox' id='hotelbox'  value='"+json[data].id+"/"+json[data].hotel+"'><\/td><td align='left' width='90px' >"+json[data].hotel+"<\/td>";
                }
                i++;
            }
            if(length%4){
                var n=2*(4-length%4);
                tempData  =  tempData +"<td colspan='"+n+"' ></td><\/tr>";
            }
            $("#showhotel").show();
            $("#hotel_ss").html(tempData);
        }else{
            alert("删除失败");
        }
    },"json");
}

function showinfo(){
    var data='{$hotelsArr}';
    var json=JSON.parse(data);
    var tempData = "";
    var length=json.length;
    var i=1;
    var per=$("#hotelname").val();
    for (var data in json){
        var checked = '';
        var patt1=new RegExp(json[data].hotel);
        var re=patt1.exec(per);
        if(re){
            checked = 'checked';
        }

        if((i%4)==1){
            tempData  =  tempData + "<tr class='ctt_white'> <td align='right'><input  type='checkbox' name='hotelbox' id='hotelbox'  value='"+json[data].id+"/"+json[data].hotel+"'" + checked +"><\/td><td align='left' width='90px'>"+json[data].hotel+"<\/td>";
        }else if((i%4)==0){
            tempData  =  tempData + " <td align='right'><input  type='checkbox' name='hotelbox' id='hotelbox'  value='"+json[data].id+"/"+json[data].hotel+"'" + checked +"><\/td><td align='left' width='90px'>"+json[data].hotel+"<\/td><\/tr>";
        }else {
            tempData  =  tempData + " <td align='right'><input  type='checkbox' name='hotelbox' id='hotelbox'  value='"+json[data].id+"/"+json[data].hotel+"'" + checked +"><\/td><td align='left' width='90px' >"+json[data].hotel+"<\/td>";
        }
        i++;
    }
    if(length%4){
        var n=2*(4-length%4);
        tempData  =  tempData +"<td colspan='"+n+"' ></td><\/tr>";
    }
    $("#showhotel").show();
    $("#hotel_ss").html(tempData);

}

function checkallhotel(o) {
    if(o.checked){
        $("input[name='hotelbox']").attr("checked",true);
    }else{
        $("input[name='hotelbox']").attr("checked",false);
    }
}

function sureclick(val){
    var flag=val;

    $("#show"+flag).hide();
    $("#show"+flag+1).hide();
    if(flag=='hotel'){
        var hotelarr="";
        $("input[name=hotelbox]:checked").each(function(){
            hotelarr+=$(this).val()+",";
        })
        //  alert(hotelarr);
        $("#hotelname").val(hotelarr);
    }else{
        var moviearr="";
        $("input[name=moviebox]:checked").each(function(){
            moviearr+=$(this).val()+",";
        })

        $("#moviename").val(moviearr);
    }
}

</script>

